package com.ruoyi.project.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.purchase.domain.pojo.ParamBean;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.purchase.domain.RyDepotDetail;
import com.ruoyi.project.purchase.service.IRyDepotDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 采供总清单明细Controller
 *
 * @author you
 * @date 2022-09-23
 */
@RestController
@RequestMapping("/purchase/ryDepotDetail")
public class RyDepotDetailController extends BaseController
{
    @Autowired
    private IRyDepotDetailService ryDepotDetailService;

    /**
     * 查询采供总清单明细列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryDepotDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(RyDepotDetail ryDepotDetail)
    {
        startPage();
        List<RyDepotDetail> list = ryDepotDetailService.selectRyDepotDetailList(ryDepotDetail);
        return getDataTable(list);
    }

    /**
     * 导出采供总清单明细列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryDepotDetail:export')")
    @Log(title = "采供总清单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RyDepotDetail ryDepotDetail)
    {
        List<RyDepotDetail> list = ryDepotDetailService.selectRyDepotDetailList(ryDepotDetail);
        ExcelUtil<RyDepotDetail> util = new ExcelUtil<RyDepotDetail>(RyDepotDetail.class);
        util.exportExcel(response, list, "采供总清单明细数据");
    }

    /**
     * 获取采供总清单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryDepotDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ryDepotDetailService.selectRyDepotDetailById(id));
    }

    /**
     * 查询可以生成订单的项目明细数据：就是purchase_order_id为空的
     */
    @GetMapping("/selectDetailForOrder")
    public AjaxResult selectDetailForOrder(ParamBean paramBean){
        return AjaxResult.success(ryDepotDetailService.selectDetailForOrder(paramBean));
    }
//    @GetMapping("/selectDetailForOrder/{id}")
//    public AjaxResult selectDetailForOrder(@PathVariable("id") Long id){
//        return AjaxResult.success(ryDepotDetailService.selectDetailForOrder(id));
//    }

    /**
     * 根据条件查询项目明细数据
     */
    @GetMapping("/selectDetailByParam")
    public AjaxResult selectDetailByParam(ParamBean paramBean){
        return AjaxResult.success(ryDepotDetailService.selectDetailByParam(paramBean));
    }

    /**
     * 根据采购订单id查询子表信息
     */
    @GetMapping("/selectBypurchaseOrderId")
    public AjaxResult selectBypurchaseOrderId(ParamBean paramBean){
        return AjaxResult.success(ryDepotDetailService.selectBypurchaseOrderId(paramBean.getLinkHeadId()));
    }

    /**
     * 新增采供总清单明细
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryDepotDetail:add')")
    @Log(title = "采供总清单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RyDepotDetail ryDepotDetail)
    {
        return toAjax(ryDepotDetailService.insertRyDepotDetail(ryDepotDetail));
    }

    /**
     * 修改采供总清单明细
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryDepotDetail:edit')")
    @Log(title = "采供总清单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RyDepotDetail ryDepotDetail)
    {
        return toAjax(ryDepotDetailService.updateRyDepotDetail(ryDepotDetail));
    }

    /**
     * 删除采供总清单明细
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryDepotDetail:remove')")
    @Log(title = "采供总清单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ryDepotDetailService.deleteRyDepotDetailByIds(ids));
    }
}
